﻿CREATE TABLE [dbo].[UserClaims] (
    [UserClaimId]     INT          IDENTITY (1, 1) NOT NULL,
    [UserId]          INT          NOT NULL,
    [ResourceId]      INT          NOT NULL,
    [ClaimTypeId]     INT          NOT NULL,
    [adt_DateCreated] DATETIME     CONSTRAINT [DF_UserClaims_adt_DateCreated] DEFAULT (getdate()) NOT NULL,
    [adt_CreatedBy]   VARCHAR (50) NULL,
    [Enabled]         INT          CONSTRAINT [DF_UserClaims_Enabled] DEFAULT ((1)) NOT NULL,
    CONSTRAINT [PK_UserClaims] PRIMARY KEY CLUSTERED ([UserClaimId] ASC),
    CONSTRAINT [FK_UserClaims_ClaimType] FOREIGN KEY ([ClaimTypeId]) REFERENCES [dbo].[ClaimType] ([ClaimTypeId]),
    CONSTRAINT [FK_UserClaims_Resource] FOREIGN KEY ([ResourceId]) REFERENCES [dbo].[Resource] ([ResourceId]),
    CONSTRAINT [FK_UserClaims_Users] FOREIGN KEY ([UserId]) REFERENCES [dbo].EnterpriseUser ([UserId])
);


GO
CREATE UNIQUE NONCLUSTERED INDEX [IX_UserClaims]
    ON [dbo].[UserClaims]([UserId] ASC, [ResourceId] ASC, [ClaimTypeId] ASC);

